$(function () {
    BASE.USER_INFO.initUserDetail();
});
var BASE = BASE||{};
BASE.USER_INFO = (function(){
    /*用户导航点击切换下面的内容*/
    $('#userContentNav').on('click','a',function () {
        var id = $(this).data('id');
        $(this).addClass('checked').siblings().removeClass('checked');
        $('#'+id).show().siblings().hide();
    });
    /*获取用户详情*/
    function initUserDetail() {
        var id = BASE.COMMON.getId();
        var sendData = {
            id:id,
        };
        var userId = BASE.COMMON.getUserId();
        if (userId){
            sendData.isSearchFollow = true;
        }
        BASE.getHttp('/device/member/detail',sendData,function (res) {
            if(res.code!=200){
                location.href='/index.html';
                return;
            }
            var result = res.data.member;
            result.isFollow = res.data.isFollow;
            var memberType = result.memberType;
            if(memberType == 'D'){ //获取评价列表及价格
                result.products = res.products;
               /* _getCommentList(1);
                return;*/
            }
            $('#userData').html(template('userData_tpl',result));
            _getNoticeList(1); //获取关注列表
        })
    }
    /*获取关注列表*/
    function _getNoticeList(page) {
        var sendData = {
            pageNum:page,
            pageSize:15,
            memberId:BASE.COMMON.getId(),
        };
        var userId = BASE.COMMON.getUserId();
        if (userId){
            sendData.needStatus = true;
        }
        BASE.apiGet('/device/mfollow/list',sendData,function (res) {
            $('#userNotice').html(template('userNotice_tpl',{data:res.list}));
            paging(res.pageNum,res.pages,_getNoticeList,'userNotice');
        })
    }
    /*获取评价列表*/
    function _getCommentList(page) {
        var sendData = {
            pageNum:page,
            pageSize:15,
            memberId:BASE.COMMON.getId(),
        };
        BASE.apiGet('/device/assess/listWithDaren',sendData,function (res) {
            $('#commentList').html(template('commentList_tpl',{data:res}));
        });
    }
    /*获取粉丝列表*/
    function getFans(page) {
        var $this = $(this);
        var flag = $this.data('flag');
        if(flag&& $this[0].toString()!=='[object Window]'){
            return;
        }
        var sendData = {
            memberId:BASE.COMMON.getId(),
            pageNum:page,
            pageSize:15,
        };
        BASE.apiGet('/device/mfollow/listFans',sendData,function (res) {
            $('#userFans').html(template('userFans_tpl',{data:res.list}));
            $this.data('flag',true);
            paging(res.pageNum,res.pages,getFans,'userFans');
        })
    }
    /*获取我的提问*/
    function getMyQuestion(page) {
        var $this = $(this);
        var type = $this.data('type');
        var flag = $this.data('flag');
        var sendData = {
            pageNum:page,
            pageSize:15,
            /* title:type || true,*/
        };
        if(flag && $this[0].toString()!=='[object Window]'){
            return;
        }
        BASE.apiGet('/device/mutualQuestion/listForMe',sendData,function (res) {
            var tpl = template('userQuestion_tpl',{data:res.list});
            $('#userQuestion .content').html(tpl);
            $this.data('flag',true).addClass('checked').siblings('.user-sub-nav-item').removeClass('checked');
            paging(res.pageNum, res.pages, getMyQuestion, 'userQuestion');
        })
    }
    /*获取我的回答*/
    function getMyAnswer(page) {
        var $this = $(this);
        var type = $this.data('type');
        var flag = $this.data('flag');
        var sendData = {
            pageNum:page,
            pageSize:15,
            memberId:BASE.COMMON.getId(),
        };
        if(flag && $this[0].toString()!=='[object Window]'){
            return;
        }
        BASE.apiGet('/device/mutualAnswer/listByMemberId',sendData,function (res) {
            var tpl = template('userAnswer_tpl',{data:res.list});
            $('#userAnswer .content').html(tpl);
            /*  $this.data('flag',true).addClass('checked').siblings('.user-sub-nav-item').removeClass('checked');*/
            paging(res.pageNum, res.pages,getMyAnswer, 'userAnswer');
        })
    }
    /*获取项目列表*/
    function getMyProject(page) {
        var $this = $(this);
        var flag = $this.data('flag');
        if(flag&& $this[0].toString()!=='[object Window]'){
            return;
        }
        var sendData = {
            pageNum:page,
            pageSize:15,
        };
        BASE.apiGet('/device/project/listForMe',sendData,function (res) {
            $('#userProject').html(template('userProject_tpl',{data:res.list}));
            $this.data('flag',true);
            paging(res.pageNum,res.pages,getMyProject,'userProject');
        })
    }
    /*我的源码*/
    function getMySource(page) {
        var $this = $(this);
        var flag = $this.data('flag');
        if(flag&& $this[0].toString()!=='[object Window]'){
            return;
        }
        var sendData = {
            pageNum:page,
            pageSize:15,
            memberId:BASE.COMMON.getId(),
        };
        BASE.apiGet('/device/sourceCode/list',sendData,function (res) {
            $('#userSource').html(template('userSource_tpl',{data:res.list}));
            $this.data('flag',true);
            paging(res.pageNum,res.pages,getMySource,'userSource');
        })
    }
    /*我的博客*/
    function getMyBlog(page) {
        var $this = $(this);
        var flag = $this.data('flag');
        if(flag&& $this[0].toString()!=='[object Window]'){
            return;
        }
        var sendData = {
            pageNum:page,
            pageSize:15,
            memberId:BASE.COMMON.getId(),
        };
        BASE.apiGet('/device/blog/list',sendData,function (res) {
            $('#userBlog').html(template('userBlog_tpl',{data:res.list}));
            $this.data('flag',true);
            paging(res.pageNum,res.pages,getMyBlog,'userBlog');
        })
    }
    return {
        initUserDetail:initUserDetail,
        getNoticeList:_getNoticeList,
        getFans:getFans,
        getMyQuestion:getMyQuestion,
        getMyAnswer:getMyAnswer,
        getMyProject:getMyProject,
        getMySource:getMySource,
        getMyBlog:getMyBlog,
    }
})();


